// pages/login/index.js

//这个页面就获取登陆用户信息   在xml里open-type="getUserInfo"     js页面里获取到用户信息然后存储起来   然后返回上一个页面

Page({
  QueryParams: { openid: '', nickName: '', gender: '', city: '', province: '', country: '', avatarUrl:''},

  onLoad: function () {
    // const openid = wx.getStorageSync('OPENID');
    // this.QueryParams.openid = openid || '';
    // this.QueryParams.nickName = this.QueryParams.nickName || '';
    // this.QueryParams.gender = this.QueryParams.gender || '';
    // this.QueryParams.city = this.QueryParams.city || '';
    // this.QueryParams.province = this.QueryParams.province || '';
    // this.QueryParams.country = this.QueryParams.country || '';
  },

  getUserInfo(e) {
    // const { openid, nickName, gender, city, province, country} = this.QueryParams;
    const { userInfo } = e.detail
    // console.log(userInfo);
    wx.setStorageSync('userinfo', userInfo);

    const openid = wx.getStorageSync('OPENID');
    this.QueryParams.openid = wx.getStorageSync('OPENID');
    this.QueryParams.nickName = userInfo.nickName;
    this.QueryParams.gender = userInfo.gender || '';
    this.QueryParams.city = userInfo.city || '';
    this.QueryParams.province = userInfo.province || '';
    this.QueryParams.country = userInfo.country || '';
    this.QueryParams.avatarUrl = userInfo.avatarUrl;
    console.log(this.QueryParams);


    wx.request({
      url: 'http://192.168.43.159:8080/user/userInfoadd',
      data: this.QueryParams
    })
    wx.navigateBack({ delta: 1 })
  }
})